package matlap.server;

import java.util.List;

import matlap.client.services.article.ArticleService;
import matlap.database.dao.ArticleDAO;
import matlap.database.dao.DAOFactory;
import matlap.shared.Article;
import matlap.shared.Author;
import matlap.shared.Topic;
import matlap.shared.exceptions.MyException;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class ArticleServiceImpl extends RemoteServiceServlet implements
		ArticleService {

	DAOFactory df = DAOFactory.getInstance();
	ArticleDAO ad = df.getArticleDAO();

	/**
	 * Turns back all of the authors name in Author list.
	 * @throws MyException 
	 */

	public List<Author> selectAuthorName() throws MyException {
		return ad.selectAuthorName();
	}

	/**
	 * Turns back all of the topics name in Topic list.
	 */

	public List<Topic> selectTopicsName() {
		return ad.selectTopicsName();
	}

	/**
	 * Turns back the articles title, author name, topic name and article text
	 * in Article list, by adding article title, topic name and author name.
	 */
	public List<Article> selectArticle(String articleName, String topicsName,
			String authorName) {
		return ad.selectArticle(articleName, topicsName, authorName);
	}

	/**
	 * Inserts an article to the article table by adding article title, author
	 * name, topic name and file name.
	 * @throws MyException 
	 */
	public boolean insertArticle(String address, String authorName,
			String topicsName, String fileName, String path) throws MyException {
		return ad.insertArticle(address, authorName, topicsName, fileName, path);
	}

	public void insertAuthor(String authorName, String localityName) {
		ad.insertAuthor(authorName, localityName);
	}

	public void insertTopic(String name) {
		ad.insertTopic(name);

	}

	public int getArticlesNumber() {
		return ad.getArticlesNumber();
	}

}